package com.itchen.homework;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author げっしょく
 * @date 2021/8/29
 */

@WebServlet("/home1")
public class homework1 extends HttpServlet {
    /*
    作业：
1. 模拟登录
    login.html:
        form
            用户名：
            密码：
            登录

    UserServlet：
        处理登录的请求
            假设正确的用户名密码如下：
                用户名为：zhangsan
                密码为：123
            如果用户名密码正确就输出登录成功
            否则输出登录失败。
     */

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置账号密码
        String user = "zhangsan";
        String pass = "123";
        //获取用户输入的账号密码
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        //判断账号密码是否正确
        if(user.equals(username) && pass.equals(password)){
            System.out.println("登录成功");
        }else{
            System.out.println("登录失败");
        }
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
